package com.manopservice.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.manopservice.dao.CarModelDAO;
import com.manopservice.model.CarBrand;
import com.manopservice.model.CarModel;

@Service("carModelService")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class CarModelServiceImpl implements CarModelService {

	@Autowired
	private CarModelDAO carModelDAO;
	
	public CarModelServiceImpl(){		
	}
	
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void addCarModel(CarModel carModel) {
		carModelDAO.save(carModel);		
	}
	
	@Transactional(propagation = Propagation.REQUIRED, readOnly = false)
	public void deleteCarModel(int id) {
		carModelDAO.delete(id);
		
	}

	public List<CarModel> listCarModels() {
		return carModelDAO.findAll();
	}

	@Override
	public CarModel findCarModelById(int id) {
		
		return carModelDAO.findById(id);
	}

	@Override
	public List<CarModel> findCarModelByCarBrand(CarBrand carBrand) {
		
		return carModelDAO.findByCarBrand(carBrand);
	}
	

}
